# encoding:utf-8

import requests
import base64
import json
'''
网络图片文字识别
'''

request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/webimage"
# 二进制方式打开图片文件
f = open('5.jpg', 'rb')
img = base64.b64encode(f.read())
access_token="24.9dedfeeda60c7bd78eb435c68a431539.2592000.1756989198.282335-119699574"
params = {"image":img}
request_url = request_url + "?access_token=" + access_token
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(request_url, data=params, headers=headers)
if response:
    content = response.json()
    # 提取所有words内容
    words_list = [item['words'] for item in content['words_result']]

    print(words_list)